﻿<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>职称设置 - 添加</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@3.3.4/dist/vue.global.min.js"></script>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <link rel="stylesheet" href="https://unpkg.com/element-plus/dist/index.css">
    <script src="https://unpkg.com/element-plus/dist/index.full.min.js"></script>
    <style>
        .nr div {
            margin: 15px;
            margin-left: 0px;
        }

        td {
            padding: 5px;
            padding-left: 0px;
        }
    </style>
</head>
<body>
    <div id="app">
        <div>您正在做的业务是：人力资源--客户化设置--人力资源档案管理设置--职称设置--职称添加</div>
        <div class="nr">
            <table>
                <tr>
                    <td>职位名称： </td>
                    <td><input type="text" size="30" v-model="majorName" /></td>
                </tr>
            </table>
            <div>
                <el-button type="primary" v-on:click="addTitle">添加</el-button>
                <el-button type="primary" v-on:click="Ret">返回</el-button>
            </div>
        </div>
    </div>

    <script>
        const { createApp, ref } = Vue;

        const app = createApp({
          setup() {
             const majorName = ref('');

             const addTitle = async () => {
                if (!majorName.value.trim()) {
                    ElementPlus.ElMessage.warning('请输入职称名称');
                    return;
                }

                try {
                    const response = await axios.post('/ZCSZ/AddTitle', {
                        name: majorName.value
                    });

                    if (response.data.success) {
                        ElementPlus.ElMessage.success('添加成功');
                        setTimeout(() => {
                            Ret();
                        }, 1000);
                    } else {
                        ElementPlus.ElMessage.error('添加失败: ' + response.data.message);
                    }
                } catch (error) {
                    console.error('添加职称失败:', error);
                    ElementPlus.ElMessage.error('添加职称失败，请重试');
                }
             };

             const Ret = () => {
                window.location.href = '/ZCSZ/Fan';
             };

             return {
                 majorName,
                 addTitle,
                 Ret
             }
          }
        });

        app.use(ElementPlus);
        app.mount('#app');
    </script>
</body>
</html>